package com.x.dao;

import com.x.pojo.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * ClassName: StudentDaoImpl
 * Package: IntelliJ IDEA
 * Description:
 * Written by HanXu
 * Create 2024.09.03 15:16
 */

@Repository
public class StudentDaoImpl implements StudentDao{

    @Autowired //就不用写set方法了
    private JdbcTemplate jdbcTemplate;
    @Override
    public List<Student> queryAll() {
        //jdbcTemplate进行数据库查询: ioc容器装配
        String sql = "select id, name, gender, age, class as classes from students ";
        List<Student> studentList = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(Student.class));
        System.out.println("StudentDao层");

        return studentList;
    }
}
